#!/usr/bin/env python3
# -*- coding=utf-8 -*-
# 本脚由亁颐堂现任明教教主编写，用于乾颐盾Python课程！
# 教主QQ:605658506
# 亁颐堂官网www.qytang.com
# 教主技术进化论拓展你的技术新边疆
# https://ke.qq.com/course/271956?tuin=24199d8a
from django.shortcuts import render
from data.fusioncharts import FusionCharts
import json



def chartsjson(request):
    return render(request, 'charts_json.html')


def fusioncharts(request):
    chart_data1 = {
                  "chart": {
                            "caption": "Router CPU Usage",
                            "yaxisname": "percent",
                            "subcaption": "[2018-8-6]",
                            "numbersuffix": "%",
                            "rotatelabels": "1",
                            "setadaptiveymin": "1",
                            "theme": "fusion"
                            },
                  "data": [
                            {
                             "label": "00:00",
                             "value": "89.45"
                            },
                            {
                             "label": "04:00",
                             "value": "89.87"
                            },
                            {
                             "label": "08:00",
                             "value": "89.64"
                            },
                            {
                             "label": "12:00",
                             "value": "90.13"
                            },
                            {
                             "label": "16:00",
                             "value": "90.67"
                            },
                            {
                             "label": "20:00",
                             "value": "90.54"
                            }
                        ]
                }
    column1d = FusionCharts(
        'line',
        'ex1',
        '600',
        '400',
        'chart-1',
        'json',
        json.dumps(chart_data1),
    )

    chart_data2 = {
                    "chart": {
                        "caption": "Countries with Highest Deforestation Rate",
                        "subcaption": "For the year 2017",
                        "yaxisname": "Deforested Area{br}(in Hectares)",
                        "decimals": "1",
                        "theme": "fusion"
                    },
                    "data": [
                        {
                            "label": "Brazil",
                            "value": "1466000"
                        },
                        {
                            "label": "Indonesia",
                            "value": "1147800"
                        },
                        {
                            "label": "Russian Federation",
                            "value": "532200"
                        },
                        {
                            "label": "Mexico",
                            "value": "395000"
                        },
                        {
                            "label": "Papua New Guinea",
                            "value": "250200"
                        },
                        {
                            "label": "Peru",
                            "value": "224600"
                        },
                        {
                            "label": "U.S.A",
                            "value": "215200"
                        },
                        {
                            "label": "Bolivia",
                            "value": "135200"
                        },
                        {
                            "label": "Sudan",
                            "value": "117807"
                        },
                        {
                            "label": "Nigeria",
                            "value": "82000"
                        }
                    ]
                }
    column2d = FusionCharts(
        'column3d',
        'ex2',
        '600',
        '400',
        'column-1',
        'json',
        json.dumps(chart_data2),
    )

    return render(request, 'fusioncharts.html',{'output1': column1d.render(), 'output2': column2d.render()})